import jaydebeapi
import phoenixdb
import phoenixdb.cursor
from sqlalchemy import create_engine
import pandas as pd


def get_oracle_engine():
    # url = 'jdbc:phoenix:10.2.111.14,10.2.111.56,10.2.111.60:2181:/hbase-unsecure'
    url = 'jdbc:phoenix:10.150.27.213:2181:/hbase-unsecure'
    # user = config.user
    # password = config.pwd
    # jar = 'C:\Program Files\squirrel-sql-snapshot-20180404_2309\lib\phoenix-4.4.0.2.3.4.0-3485-client.jar'
    jar = 'C:\Program Files\squirrel-sql-snapshot-20180404_2309\lib\phoenix-4.9.0-HBase-1.1-client.jar'
    connection = jaydebeapi.connect('org.apache.phoenix.jdbc.PhoenixDriver',
                                    [url, None, None], jar)
    return connection


def cal_dis():
    database_url = 'http://10.2.111.51:8765/'
    # result = pd.read_sql_query(" select count(0) from T_QWXT_PM ", get_oracle_engine())
    # result = pd.read_sql_query(" select * from EHL_GPS limit 10 ", get_oracle_engine())
    # return
    conn = phoenixdb.connect(database_url, autocommit=True)

    # print('ok')
    cursor = conn.cursor()
    cursor.execute("select * from EHL_GPS limit 10")
    print(cursor.fetchone())
    # cursor.fetchall()
    #
    # cursor = conn.cursor(cursor_factory=phoenixdb.cursor.DictCursor)
    # cursor.execute("SELECT * FROM users WHERE id=1")
    # print
    # cursor.fetchone()['USERNAME']


if __name__ == '__main__':
    get_oracle_engine()
